import { TTenantType } from '@/datatypes/tTenant/data';
import { list } from '@/services'; // 假设这是你的服务端请求库
import { tTenantUrl } from '@/urls'; // 假设这是你的租户数据类型
import { useEffect, useState } from 'react';

export const useTenants = () => {
  const [tenants, setTenants] = useState<TTenantType[]>([]);

  useEffect(() => {
    list(tTenantUrl).then((data: any) => {
      setTenants(data?.list || []);
    });
  }, []);

  return tenants;
};

export const getTenantOptions = (tenants: TTenantType[]) => {
  return tenants.map((tenant) => ({
    value: tenant.id,
    label: tenant.name,
  }));
};

export const generateValueEnum = (tenants: TTenantType[]): Record<string, { text: string }> => {
  return tenants.reduce((acc, tenant) => {
    acc[tenant.id] = { text: tenant.name };
    return acc;
  }, {} as Record<string, { text: string }>);
};
